package com.controller.manage;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.po.Permission;
import com.service.manage.PermissionService;
import com.util.UUIDGenerator;

@Controller
@RequestMapping("/jsp/manager")
public class PermissionController {

	@Resource(name="permissionServiceImp")
	public PermissionService permissionService;
	
	@ResponseBody
	@RequestMapping(value="/getPermissionList")
	public Map<String,Object> getPermission(Permission permission,Integer page,Integer rows){
		
		permission.setPage((page-1)*rows);
		permission.setRows(rows);
		List<Permission> list = permissionService.getPermissionList(permission);
		int count = permissionService.getPermissionCount(permission);
		Map<String,Object> map = new HashMap<String,Object>();
		 map.put("total", count);
		 map.put("rows", list);
		return map;
	}
	
	@ResponseBody
	@RequestMapping(value="/addPermission")
	public int addPermission(Permission permission){
		permission.setPermissionid(UUIDGenerator.getUUID());
		int result = permissionService.addPermission(permission);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value="/delPermission")
	public int delPermission(Permission permission){
		
		int result = permissionService.delPermission(permission);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value="/delPermissionList")
	public int delPermissionList(String permissionids){
		
		String[] array = permissionids.split(",");
		int result = permissionService.delPermissionList(array);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value="/updatePermission")
	public int updatePermission(Permission permission){
		
		int result = permissionService.updatePermission(permission);
		return result;
	}
}
